n= int(input())
list_ss=[]
for i in range(n):
    lsit1=(input().split())
    print(lsit1)
    list_ss.append(lsit1)
    print(list_ss)

list_ss=sorted(list_ss, key= lambda x: x[0])
print(list_ss)
stack=[]
lst_str=[]

for i in range(n):
    if lst_str==[]:
        lst_str=(list_ss[i][0:2])
    elif lst_str[1]>=list_ss[i][0]:
        lst_str[0]=list_ss[i][0]
    elif lst_str[1]<list_ss[i][0]:
        stack.append(lst_str)

    # if stack==[]:
    #     stack.append(list_ss[i][0:2])
    # else:
    #     if stack[-1][-1] >= list_ss[i][0]:
    #         stack[-1] [-1] = max(list_ss[i][1],stack[-1][-1])
    #     else:
    #         stack.append(list_ss[i][0:2])

for i in range(n):



